<%@ page language="java"  contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<title>选择角色</title>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/header.jsp" %>
<%@ include file="/extjs/jsps/importExt.jsp" %>
<%@ include file="/extjs/jsps/importEasyExt.jsp" %>
<script type="text/javascript" src="${ctx }/extjs/easyext/ux/TreeCheckNodeUI.min.js"></script>
<script language="javascript" type="text/javascript">
function closeCurrentWindow(returnValue) {
	var winId='${winId}';
	var closeWin=Ext.WindowMgr.get(winId);
	if(closeWin==null){
		closeWin=parent.Ext.WindowMgr.get(winId);
	}
	if(closeWin==null){
		window.returnValue=returnValue;
		window.close();
	}else{
		closeWin.returnValue=returnValue;
		closeWin.close();
	}
}

var treePanel = new Ext.tree.TreePanel({
	style: 'text-align:left;',
	autoScroll: true,
	enableDD: false,
	containerScroll: true,
	frame: false,
	animate: true,
	rootVisible: false,
	onlyLeafCheckable: false,
    root: new Ext.tree.AsyncTreeNode({
		id: '1',
		text: 'ROOT',
		leaf: false,
		expanded: true
    }),
	loader: new Ext.tree.TreeLoader({
		url: '${ctx}/role!listJSON.action',
		baseAttrs: {
			uiProvider: Ext.ux.TreeCheckNodeUI
		}
	}),
	bbar: [{
		text: '确定',
		iconCls: 'acceptBtn',
		handler: function () {
			var array=new Array();
			treePanel.getRootNode().cascade(function(n) {
				if(n.attributes.checked) {
					var obj=new Object();
					obj.id=n.id;
					array.push(obj);
				}
			    return true;
			});
			if(array.length==0) {
				Common.showErrorMsg('请至少选择一个角色！');
				return;
			}
			closeCurrentWindow(array);
		}
	},'-',{
		iconCls: 'delete2Btn',
		text: '取消',
		handler: function() {
			closeCurrentWindow(false);
		}
	}]
});

Ext.onReady(function() {

	var viewport = new Ext.Viewport({
		layout: 'fit',
		items: [treePanel]
	});
});
</script>
</head>

<body>
</body>
</html>
